package com.zlq.dao;


import com.zlq.pojo.LoginInfo;
import com.zlq.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class LoginInfoDao {


    //注入 JdbcTemplate
    @Autowired
    private JdbcTemplate jdbcTemplate;



    public List<LoginInfo> findAllLog(){
        String sql = "select * from login_info";
        List<LoginInfo> infoList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<LoginInfo>(LoginInfo.class));
        return infoList;

    }

    public void insertLog(LoginInfo loginInfo){

        String sql = "insert into login_info values(?,?,?)";

        String[] args = {loginInfo.getUsername(),loginInfo.getIp(),loginInfo.getLogintime()};

        int update = jdbcTemplate.update(sql, args);

        System.out.println(update);
    }

}


















